﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Devdream.BLL;
using Devdream.Models;
namespace Devdream.Web.Areas.Member.Controllers
{
    public class UserManagerController : Controller
    {
        // GET: Member/UserManager
        UserService userServer = new UserService();
        public ActionResult Details()
        {
            return View(userServer.Find(User.Identity.Name));
        }
        /// <summary>
        /// 用户信息修改
        /// </summary>
        /// <returns></returns>
        [ValidateAntiForgeryToken]
        [HttpPost]
        public ActionResult Modify()
        {
            var user = userServer.Find(User.Identity.Name);
            if (user == null)
                ModelState.AddModelError("", "用户名不存在");
            else
            {
               if (TryUpdateModel(user, new string[] { "DisplayName", "Email" }))
                {
                    if (ModelState.IsValid)
                    {
                        if (userServer.Update(user)) ModelState.AddModelError("", "修改成功！");
                        else ModelState.AddModelError("", "无需要修改的资料");
                    }
                }
                else ModelState.AddModelError("", "更新模型数据失败");
            }
            return View("Details", user);
            }
           
        
    }
}